package org.ru.mse10.cvis.entity.cv.custom;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.ru.mse10.cvis.entity.cv.custom.provider.CustomFieldValueProvider;
import org.ru.mse10.cvis.entity.misc.Identity;
import org.ru.mse10.cvis.entity.util.CustomFieldType;

/**
 * The Class CustomField.
 */
@Entity
@Table(name = "custom_field")
public class CustomField extends Identity {

	/** The field key. */
	private String fieldKey;

	/** The display name. */
	private String displayName;

	/** The description. */
	private String description;

	/** The field type. */
	private CustomFieldType fieldType = CustomFieldType.getDefault();

	/** The simple values. */
	private List<CustomFieldValue> simpleValues = new ArrayList<CustomFieldValue>();

	/** The value provider. */
	private CustomFieldValueProvider valueProvider;

	/** The required. */
	private Boolean required;

	/**
	 * Gets the field key.
	 * 
	 * @return the field key
	 */
	public String getFieldKey() {
		return fieldKey;
	}

	/**
	 * Sets the field key.
	 * 
	 * @param fieldKey
	 *            the new field key
	 */
	public void setFieldKey(String fieldKey) {
		this.fieldKey = fieldKey;
	}

	/**
	 * Gets the display name.
	 * 
	 * @return the display name
	 */
	public String getDisplayName() {
		return displayName;
	}

	/**
	 * Sets the display name.
	 * 
	 * @param displayName
	 *            the new display name
	 */
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	/**
	 * Gets the description.
	 * 
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the description.
	 * 
	 * @param description
	 *            the new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the field type.
	 * 
	 * @return the field type
	 */
	public CustomFieldType getFieldType() {
		return fieldType;
	}

	/**
	 * Sets the field type.
	 * 
	 * @param fieldType
	 *            the new field type
	 */
	public void setFieldType(CustomFieldType fieldType) {
		this.fieldType = fieldType;
	}

	/**
	 * Gets the value provider.
	 * 
	 * @return the value provider
	 */
	@OneToOne(cascade = CascadeType.ALL)
	public CustomFieldValueProvider getValueProvider() {
		return valueProvider;
	}

	/**
	 * Sets the value provider.
	 * 
	 * @param valueProvider
	 *            the new value provider
	 */
	public void setValueProvider(CustomFieldValueProvider valueProvider) {
		this.valueProvider = valueProvider;
	}

	/**
	 * Gets the simple values.
	 * 
	 * @return the simple values
	 */
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "field", orphanRemoval = true)
	public List<CustomFieldValue> getSimpleValues() {
		return simpleValues;
	}

	/**
	 * Sets the simple values.
	 * 
	 * @param simpleValues
	 *            the new simple values
	 */
	public void setSimpleValues(List<CustomFieldValue> simpleValues) {
		this.simpleValues = simpleValues;
	}

	/**
	 * Gets the required.
	 * 
	 * @return the required
	 */
	public Boolean getRequired() {
		return Boolean.TRUE == required;
	}

	/**
	 * Sets the required.
	 * 
	 * @param required
	 *            the new required
	 */
	public void setRequired(Boolean required) {
		this.required = required;
	}

}
